package com.panshi.controller;

import com.panshi.api.IUserService;
import com.panshi.vo.ResponseVO;
import com.panshi.vo.UserVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@Api(tags = "用户信息中心接口")
public class UserCenterController {

    @Autowired
    IUserService userService; //用户service层
    /**
     * 修改用户信息
     * @param uid
     * @param nick
     * @param userDesc
     * @param logo
     * @return
     */
    @RequestMapping(value = "/user/updateUserInfo")
    @ResponseBody
    public UserVO updateUserInfo(@RequestParam String uid,@RequestParam String nick,@RequestParam String userDesc,@RequestParam String logo){
        System.out.println("privoder层controller拿到的loginuserid:"+uid);
        //改变用户
        userService.updateUserInfo(uid,nick,userDesc,logo);
        //查询该用户
        return userService.findUserByuid(uid);
    }
    /**
     * 修改用户密码
     * @param uid
     * @param pwd
     * @return
     */
    @RequestMapping("/user_page/update/updatePwd")
    @ResponseBody
    public ResponseVO updateUserPwd(@RequestParam String uid,@RequestParam String pwd){
        //将传过来的参数封装进UserVO对象
        UserVO user = new UserVO();
        user.setU_id(Integer.valueOf(uid));
        user.setU_password(pwd);

        userService.updateUserPwd(user);

        ResponseVO rs = new ResponseVO();
        rs.setMsg("修改密码成功！");
        rs.setState(200);
        rs.setSuccess(true);
        return rs;
    }

    @RequestMapping("/user_page/update/updateEmail")
    @ResponseBody
    public ResponseVO updateUserEmail(@RequestParam String uid, @RequestParam String newMail){
        //将传过来的参数封装进UserVO对象
        UserVO user = new UserVO();
        user.setU_id(Integer.valueOf(uid));
        user.setU_mail(newMail);

        userService.updateUserEmail(user);

        ResponseVO rs = new ResponseVO();
        rs.setMsg("修改邮箱成功！");
        rs.setState(200);
        rs.setSuccess(true);
        return rs;
    }
}
